package com.ruoyi.web.controller.swimming;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swimming.domian.ActivityJoiner;
import com.ruoyi.swimming.service.IActivityJoinerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 活动参与人Controller
 * 
 * @author ruoyi
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/system/joiner")
public class ActivityJoinerController extends BaseController
{
    @Autowired
    private IActivityJoinerService activityJoinerService;

    /**
     * 查询活动参与人列表
     */
    @PreAuthorize("@ss.hasPermi('system:joiner:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityJoiner activityJoiner)
    {
        startPage();
        List<ActivityJoiner> list = activityJoinerService.selectActivityJoinerList(activityJoiner);
        return getDataTable(list);
    }

    /**
     * 导出活动参与人列表
     */
    @PreAuthorize("@ss.hasPermi('system:joiner:export')")
    @Log(title = "活动参与人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ActivityJoiner activityJoiner)
    {
        List<ActivityJoiner> list = activityJoinerService.selectActivityJoinerList(activityJoiner);
        ExcelUtil<ActivityJoiner> util = new ExcelUtil<ActivityJoiner>(ActivityJoiner.class);
        return util.exportExcel(list, "活动参与人数据");
    }

    /**
     * 获取活动参与人详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:joiner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(activityJoinerService.selectActivityJoinerById(id));
    }

    /**
     * 新增活动参与人
     */
    @PreAuthorize("@ss.hasPermi('system:joiner:add')")
    @Log(title = "活动参与人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityJoiner activityJoiner)
    {
        return toAjax(activityJoinerService.insertActivityJoiner(activityJoiner));
    }

    /**
     * 修改活动参与人
     */
    @PreAuthorize("@ss.hasPermi('system:joiner:edit')")
    @Log(title = "活动参与人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityJoiner activityJoiner)
    {
        return toAjax(activityJoinerService.updateActivityJoiner(activityJoiner));
    }

    /**
     * 删除活动参与人
     */
    @PreAuthorize("@ss.hasPermi('system:joiner:remove')")
    @Log(title = "活动参与人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(activityJoinerService.deleteActivityJoinerByIds(ids));
    }
}
